package com.loong.android.sqlite.data;

import android.database.sqlite.SQLiteDatabase;
import android.text.TextUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2020/3/24.
 */

public class DbData {
    //数据库名称
    private String dbName;
    //数据库文件名称，带.db后缀
    private String dbFileName;

    //数据库
    private SQLiteDatabase sqLiteDatabase;
    //表数组
    private List<TableData> tableList = new ArrayList<>();
    private int version = 1;

    public String getDbName() {
        return dbName;
    }

    public void setDbName(String dbName) {
        this.dbName = dbName;
    }

    public String getDbFileName() {
        return dbFileName;
    }

    public void setDbFileName(String dbFileName) {
        this.dbFileName = dbFileName;
    }

    public SQLiteDatabase getSqLiteDatabase() {
        return sqLiteDatabase;
    }

    public void setSqLiteDatabase(SQLiteDatabase sqLiteDatabase) {
        this.sqLiteDatabase = sqLiteDatabase;
    }

    public List<TableData> getTableList() {
        return tableList;
    }

    public void setTableList(List<TableData> tableList) {
        this.tableList = tableList;
    }

    public int getVersion() {
        return version;
    }

    public void setVersion(int version) {
        this.version = version;
    }

    public void addTableData(TableData tableData) {
        if (tableList == null) tableList = new ArrayList<>();
        tableList.add(tableData);
    }

    public void removeTable(String tableName) {
        if (tableList == null || tableList.size() <= 0) return;
        int len = tableList.size();
        for (int i=0; i<len; i++) {
            TableData tableData = tableList.get(i);
            if (tableData == null || TextUtils.isEmpty(tableData.getTableName())) continue;
            if (!tableData.getTableName().equals(tableName)) continue;
            tableList.remove(i);
            break;
        }
    }

    public void clearTable() {
        if (tableList == null) return;
        tableList.clear();
    }
}
